﻿<Window x:Class="_12.BindToList.SimpleList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SimpleList" Height="259" Width="348">
    <Window.Resources>
        <Thickness x:Key="margin" Left="5" Top="5" Right="5" Bottom="5"/>
        <Style TargetType="Label">
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Background" Value="GreenYellow"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="black"/>
        </Style>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="{StaticResource margin}"/>
            <Setter Property="Background" Value="PaleTurquoise"/>
        </Style>
    </Window.Resources>
    <Grid Name="gridTeam">
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" />
            <RowDefinition Height="1*" />
            <RowDefinition Height="1*" />
            <RowDefinition Height="1*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="1.5*" />
            <ColumnDefinition Width="1.5*" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="Members: " />
        <Label Grid.Row="1" Grid.Column="0" Content="Name: " />
        <Label Grid.Row="2" Grid.Column="0" Content="Age: " />
        <!--note: 'IsSynchronizedWithCurrentItem' means this listbox is synchronized with
        current item, change on list will affect background collection,
        change on background collection will also affect foreground list-->
        <!--note: and {Binding} without 'Source' means that the data source comes from the parent
        and if you want to select a property to show on the screen, you should specify
        'DisplayMemberPath', not 'Path', and it should be a property of ListBox
        other than a property of the 'Binding' property-->
        <ListBox Grid.Column="1" Grid.ColumnSpan="2" Margin="{StaticResource margin}" 
                 ItemsSource="{Binding}"
                 DisplayMemberPath="Name"
                 IsSynchronizedWithCurrentItem="True"/>
        <!--note: actually, compare with 'ItemSource=Binding' with 'Text=Binding Path=xxx'
        the first expression means binding to the entire list
        while the second menas binding to the current item in the datasource list-->
        <TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"  
                 Text="{Binding Path=Name}"/>
        <TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" 
                 Text="{Binding Path=Age}"/>
        <Button Name="btnNext" Content="Next" Grid.Column="1" Grid.Row="3"
                Click="btnNext_Click"/>
        <Button  Name="btnPrevious" Content="Previous" Grid.Column="2" Grid.Row="3"  
                 Click="btnPrevious_Click"/>
    </Grid>
</Window>
